#include "myqtitk.h"
#include "registration.h"

MyQtItk::MyQtItk(QWidget *parent, Qt::WFlags flags)
	: QMainWindow(parent, flags)
{
	ui.setupUi(this);

	createActions();
	createMenus();
	createToolBars();
	createStatusBar();
	//setWindowTitle(tr("ITK"));
	setUnifiedTitleAndToolBarOnMac(true);
	HasARegistrationProject = false;
}

MyQtItk::~MyQtItk()
{

}

void MyQtItk::createActions()
{
	registrationAct = new QAction(QIcon("../images/new.png"), tr("&Registration"), this);
	registrationAct->setStatusTip(tr("Create a registration project"));
	connect(registrationAct, SIGNAL(triggered()), this, SLOT(createRegistration()));

	segmentationAct = new QAction(QIcon("../images/new.png"), tr("&Segmentation"), this);
	segmentationAct->setStatusTip(tr("Create a segmentation project"));
	connect(segmentationAct, SIGNAL(triggered()), this, SLOT(createSegmentation()));
	
	restructionAct = new QAction(QIcon("../images/new.png"), tr("&Restruction"), this);
	restructionAct->setStatusTip(tr("Create a restruction project"));
	connect(restructionAct, SIGNAL(triggered()), this, SLOT(createRestruction()));

	openAct = new QAction(QIcon("../images/new.png"), tr("&Open"), this);
	openAct->setStatusTip(tr("open a project"));
	connect(openAct, SIGNAL(triggered()), this, SLOT(open()));

	saveAct = new QAction(QIcon("../images/new.png"), tr("&Save"), this);
	saveAct->setStatusTip(tr("save"));
	connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));

	saveasAct = new QAction(QIcon("../images/new.png"), tr("&Save As"), this);
	saveasAct->setStatusTip(tr("save as"));
	connect(saveasAct, SIGNAL(triggered()), this, SLOT(saveas()));

	printAct = new QAction(QIcon("../images/new.png"), tr("&Print"), this);
	printAct->setStatusTip(tr("print"));
	connect(printAct, SIGNAL(triggered()), this, SLOT(print()));

	quitAct = new QAction(QIcon("../images/new.png"), tr("&Quit"), this);
	quitAct->setShortcuts(QKeySequence::Quit);
	quitAct->setStatusTip(tr("quit"));
	connect(quitAct, SIGNAL(triggered()), this, SLOT(quit()));

	subregistration1Act = new QAction(QIcon(":/images/new.png"), tr("&Algorithm1"), this);
	subregistration1Act->setStatusTip(tr("registration algorithm 1"));
	connect(subregistration1Act, SIGNAL(triggered()), this, SLOT(registrationAlgorithm1()));

	subregistration2Act = new QAction(QIcon(":/images/new.png"), tr("&Algorithm2"), this);
	subregistration2Act->setStatusTip(tr("registration algorithm 2"));
	connect(subregistration2Act, SIGNAL(triggered()), this, SLOT(registrationAlgorithm2()));

	subregistration3Act = new QAction(QIcon(":/images/new.png"), tr("&Algorithm3"), this);
	subregistration3Act->setStatusTip(tr("registration algorithm 3"));
	connect(subregistration3Act, SIGNAL(triggered()), this, SLOT(registrationAlgorithm3()));

	registrationToCompareAct = new QAction(QIcon(":/images/new.png"), tr("&Compare View"), this);
	registrationToCompareAct->setStatusTip(tr("registration compare"));
	connect(registrationToCompareAct, SIGNAL(triggered()), this, SLOT(registrationToCompare()));

	compareToRegistrationAct = new QAction(QIcon(":/images/new.png"), tr("&Registration View"), this);
	compareToRegistrationAct->setStatusTip(tr("registration compare"));
	connect(compareToRegistrationAct, SIGNAL(triggered()), this, SLOT(compareToRegistration()));
}

void MyQtItk::createMenus()
{
	fileMenu = menuBar()->addMenu(tr("&File"));	
	newMenu = fileMenu->addMenu(tr("&New"));
	newMenu->addAction(registrationAct);
	newMenu->addAction(segmentationAct);
	newMenu->addAction(restructionAct);
	fileMenu->addAction(openAct);
	fileMenu->addAction(saveAct);
	fileMenu->addAction(saveasAct);
	fileMenu->addAction(printAct);
	fileMenu->addAction(quitAct);

	viewMenu = menuBar()->addMenu(tr("&View"));

	registrationMenu = menuBar()->addMenu(tr("&Registration"));
	subregistration1Menu = registrationMenu->addMenu(tr("&Choose Alogrithm"));
	subregistration1Menu->addAction(subregistration1Act);
	subregistration1Menu->addAction(subregistration2Act);
	subregistration1Menu->addAction(subregistration3Act);
	registrationMenu->addAction(registrationToCompareAct);
	registrationMenu->addAction(compareToRegistrationAct);

	segmentationMenu = menuBar()->addMenu(tr("&Segmentation"));

	restructionMenu = menuBar()->addMenu(tr("&Restruction"));

	helpMenu = menuBar()->addMenu(tr("&Help"));

}

void MyQtItk::createToolBars()
{
	fileToolBar = addToolBar(tr("File"));
	fileToolBar->addAction(openAct);
	fileToolBar->addAction(saveAct);
	fileToolBar->addAction(saveasAct);
	fileToolBar->addAction(printAct);
	fileToolBar->addAction(quitAct);
}

void MyQtItk::createStatusBar()
{
//	statusBar()->showMessage(tr("Ready"));
}


void MyQtItk::createRegistration()
{
	regidialog *resdialog = new regidialog(this);
	resdialog->exec();

	if(resdialog->okButtonClick)
	{
		if(HasARegistrationProject == false)
		{
			reg = new RegistrationClass();
			reg->loadNewRegistrationProject(this, viewMenu, tr("myproject"), resdialog->image1FilePath, resdialog->image2FilePath);
			registrationToCompareAct->setEnabled(true);
			compareToRegistrationAct->setEnabled(false);
		}
		else
		{
			QMessageBox::about(this, tr("Save Project?"),tr("Do you want to save your registration project?"));
		//delete reg;
		//reg = new RegistrationClass();
		}
	}
}

void MyQtItk::createSegmentation()
{
	QMessageBox::about(this, tr("About Dock Widgets"),
            tr("create new segmentation project"));
}

void MyQtItk::createRestruction()
{
	QMessageBox::about(this, tr("About Dock Widgets"),
            tr("create new restruction project"));
}

void MyQtItk::open()
{
	QMessageBox::about(this, tr("About Dock Widgets"),
            tr("open"));
}
	
void MyQtItk::save()
{
	QMessageBox::about(this, tr("About Dock Widgets"),
            tr("save"));
}
	
void MyQtItk::saveas()
{
	QMessageBox::about(this, tr("About Dock Widgets"),
            tr("save as"));
}
	
void MyQtItk::print()
{
	QMessageBox::about(this, tr("About Dock Widgets"),
            tr("print"));
}
	
void MyQtItk::quit()
{
	QMessageBox::about(this, tr("About Dock Widgets"),
            tr("quit"));
}
	
void MyQtItk::registrationAlgorithm1()
{
	QMessageBox::about(this, tr("About Dock Widgets"),
            tr("registration algorithm 1"));
}
	
void MyQtItk::registrationAlgorithm2()
{
	QMessageBox::about(this, tr("About Dock Widgets"),
            tr("registration algorithm 2"));
}
	
void MyQtItk::registrationAlgorithm3()
{
	QMessageBox::about(this, tr("About Dock Widgets"),
            tr("registration algorithm 3"));
}
	
void MyQtItk::registrationToCompare()
{
	reg->showCompareResult(this);
	registrationToCompareAct->setEnabled(false);
	compareToRegistrationAct->setEnabled(true);
	
}
void MyQtItk::compareToRegistration()
{
	reg->showRegistrationResult(this);
	registrationToCompareAct->setEnabled(true);
	compareToRegistrationAct->setEnabled(false);

}